//gcc notify.c -o notify `pkg-config glib-2.0 dbus-glib-1 --cflags --libs`

#define DBUS_API_SUBJECT_TO_CHANGE

#include <glib.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>

int
main (int argc, char **argv)
{
   DBusGConnection *connection;
   GError *error;
   DBusGProxy *proxy;
   char **device_list;
   char **device_list_ptr;
   int return_value;
   char *icon;
   char *summary;
   char *description;
   
   g_type_init();
   
   error = NULL;
   connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
   
   if (connection == NULL) {
      g_printerr("Failed to open connection to bus: %s\n", error->message);
      g_error_free(error);
      exit(1);
   }
   
   proxy = dbus_g_proxy_new_for_name (connection,
                                      "org.freedesktop.Notifications",
                                      "/org/freedesktop/Notifications",
                                      "org.freedesktop.Notifications");

   icon = "/usr/share/icons/Tango/scalable/devices/harddrive.svg";
   summary = "Harddisk em Chamas!";
	description = "Parece que seu hardisk queimou de vez.";

   error = NULL;
   if (!dbus_g_proxy_call (proxy, "Notify", &error,
                           G_TYPE_STRING, "minha-app-c",
                           G_TYPE_UINT, 0,
                           G_TYPE_STRING, icon,
                           G_TYPE_STRING, summary,
                           G_TYPE_STRING, description,
                           G_TYPE_STRV, "",
                           dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
                                               G_TYPE_VALUE), NULL,
                           G_TYPE_INT, 5000,
                           G_TYPE_INVALID,
                           G_TYPE_UINT, &return_value,
                           G_TYPE_INVALID)) {

      if (error->domain == DBUS_GERROR && 
          error->code == DBUS_GERROR_REMOTE_EXCEPTION)
         g_printerr ("Caught remote method exception %s: %s",
                     dbus_g_error_get_name(error),
                     error->message);
      else
         g_printerr("Error %s\n", error->message);

      g_error_free(error);
      exit(1);
   }
   
   g_print("%d\n", return_value);
   
   g_object_unref(proxy);

   return 0;
}
